package com.tianjian.dao.impl;


import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import com.tianjia.entity.Company;
import com.tianjia.uitl.DBManager;

public class CompanyDaoImpl {//瀹炵幇绫� 璧峰悕:瀹炵幇绫诲悕DaoImpl
	public Company getCompany() {
		Connection conn = DBManager.getConnection();//创建连接
		//全局变量
		Statement st = null;
		ResultSet rs = null;
		Company company = null;
		
		try {//正常执行
			//创建Statement执行对象,作用是执行sql语句
			st = conn.createStatement();
			//执行sql语句
			rs = st.executeQuery("select * from Company");
			//遍历结果集
			while(rs.next()) {
				String name= rs.getString("name");
				String webSite= rs.getString("webSite");
				String introduction= rs.getString("introduction");
				String phone= rs.getString("phone");
				String email= rs.getString("email");
				String address= rs.getString("address");
				String culture= rs.getString("culture");
				String logo= rs.getString("logo");
				//创建company对象
				company = new Company(name, webSite, introduction, phone, email, address, culture, logo);
			}
			return company;//正常返回company
		} catch (SQLException e) {//异常执行
			e.printStackTrace();
			return null;//异常情况下返回null
		}finally {//关闭流
			DBManager.closeAll(conn, st, rs);
		}
	}
}
